package com.adingxiong.cft.quartz;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @ClassName InjectJobDemo
 * @Description   数据传递之 javabean 字段映射
 * @Author xiongchao
 * @Date 2021/1/11 15:15
 **/
@Slf4j
public class InjectJobDemo {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        JobDetail jobDetail = JobBuilder.newJob(InjectJob.class)
                .withIdentity("inject", "group01")
                .usingJobData("name","设置名称属性")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("inject_group")
                .startNow()
                .build();

        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.scheduleJob(jobDetail,trigger);

        scheduler.start();

        Thread.sleep(2_100);
        scheduler.shutdown();
    }

    public static class InjectJob implements Job{

        private String name ;

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            log.info("------------------------ dataJob ----------------------");
            log.info("从定时任务中读取到的数据为：{}" ,name);
            log.info("------------------------ dataJob ----------------------");
        }
    }
}
